﻿using WebApiClient.Contexts;
using System.Threading.Tasks;
using WebApiClient.Attributes;
using Microsoft.Extensions.Configuration;

namespace ARchGL.Platform.Jianwei
{
    #region 实名制

    /// <summary>
    /// 服务端
    /// </summary>
    public class RealServerDefaultHeaderAttribute : ApiActionFilterAttribute
    {
        private IConfigurationRoot appConfiguration;

        public RealServerDefaultHeaderAttribute(IConfigurationRoot _appConfiguration)
        {
            appConfiguration = _appConfiguration;
        }

        public override async Task OnBeginRequestAsync(ApiActionContext context)
        {
            await base.OnBeginRequestAsync(context);
        }

        public override Task OnEndRequestAsync(ApiActionContext context)
        {
            return base.OnEndRequestAsync(context);
        }
    }

    /// <summary>
    /// 设备终端
    /// </summary>
    public class RealClientDefaultHeaderAttribute : ApiActionFilterAttribute
    {
        private IConfigurationRoot appConfiguration;

        public RealClientDefaultHeaderAttribute(IConfigurationRoot _appConfiguration)
        {
            appConfiguration = _appConfiguration;
        }

        public override async Task OnBeginRequestAsync(ApiActionContext context)
        {
            context.RequestMessage.AddUrlQuery("sn", appConfiguration["Jianwei:RealSN"]);
            //context.RequestMessage.AddUrlQuery("token", RefreshTokenService.GetTowerCraneAndHoistAccessToken());// 

            await base.OnBeginRequestAsync(context);
        }

        public override Task OnEndRequestAsync(ApiActionContext context)
        {
            return base.OnEndRequestAsync(context);
        }
    }

    #endregion
}
